OA = function(obj){	return OA.anew(obj);}
OA.anew = function(obj){this.obj=obj;	return this;}

//--公告
OA.placard = function(obj){	return OA.placard.anew(obj);}
OA.placard.anew = function(obj){this.obj=obj;	return this;}
OA.placard.rule_show = function(filename){
	var obj=Object();
	obj.id='ajax_daily';
	obj["class"]='acan_win dis_none';
	obj.css={height:'650px',width:'90%'};
	obj._close={onclick:'Acan.close(\''+obj.id+'\')','class':'-close'};//关闭按钮
	var html = Ahtml.tag('iframe',{style:'overflow:auto;position:absolute;top:0px;bottom:0;border:0;left:0;right:0;width:100%;height:100%;','src':'/plugin/FlexPaper/php/oa_rule.php?doc='+filename});
	var title = filename;
	Acan.base.win(obj,title,html);
	Acan.ajax_bg();
}


//--日程
OA.daily = function(obj){	return OA.daily.anew(obj);}
OA.daily.anew = function(obj){this.obj=obj;	return this;}
//--检查是否有未读日报
OA.daily.check = function(){
	jQuery.ajax({type: "GET",url: Aurl.App+"-work-daily_new",data: "",
		success: function(data){
			if(data.num>0){
				if(jQuery(".a_menu .-warn ._oa", window.parent.document).length == 0){
					jQuery(".a_menu .-warn", window.parent.document).append(Ahtml.tag('div',{'class':"_oa"}));
				}
				var oa_warn = jQuery(".a_menu .-warn ._oa", window.parent.document);
				var html = Ahtml.tag('p',{'class':'-red _yellow'},'您有'+data.num+'封日报未读!');
				oa_warn.html(html);
			}else{
				jQuery(".a_menu .-warn ._oa", window.parent.document).html("");
			}
		}
	})
	setTimeout("OA.daily.check()",5*1000);
}

OA.daily.show = function(title,html,css){
	var obj=Object();
	obj.id='ajax_daily';
	obj["class"]='acan_win dis_none';
	obj.css={height:'auto',width:'auto'};
	if(css){obj.css=css};
	obj._close={onclick:'Acan.close(\''+obj.id+'\')','class':'-close'};//关闭按钮
	Acan.base.win(obj,title,html);
	Acan.ajax_bg();
}
//--显示已发日报
OA.daily.view = function(id){
	var title = '日报';
	var css = {width:"640px",height:"auto"}
	jQuery.ajax({
		type: "GET",
		url: "/"+Aurl.Amodr+'-daily_view-'+id,
		data: '',
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			Acan.alert();
			OA.daily.show(data.title,Ahtml.tag('div',{"class":'_daily_view'},data.note),css);
			if(jQuery("._daily_"+id)) jQuery("._daily_"+id).css('background','#e7e7e7');
		}
	})
}
OA.daily.userlist = function(){
	var val = Acan.base.json_obj(jQuery("._add input[name=\"save[recv]\"]").val());
	var html = '';
	var obj = {type:'checkbox',name:'group[]'};
	for(var g in userdata['enum']){
		if(userdata.data[g]){
			html += Ahtml.tag('dt',{},userdata['enum'][g]+':')+Ahtml.tag('dd',{},Ahtml.inputs(obj,userdata.data[g],val));
		}
	}
	html += Ahtml.tag('dt',{})+Ahtml.tag('dd',{},Ahtml.tag('input',{type:"button",value:'确定',onclick:'OA.daily.userlist_ok()'}));
	html = Ahtml.tag('dl',{'class':"-dl"},html);
	html = Ahtml.tag('form',{'class':'_userlist'},html);
	var title = '用户列表';
	var css = {width:"500px",height:"auto"}
	OA.daily.show(title,html,css);
}
OA.daily.userlist_ok = function(){
	var obj = jQuery('#ajax_daily form');
	var drr = obj.serializeArray();
	if(typeof(drr)=='object'){
		var group = Array();
		for(var i in drr){
			group[i] = drr[i].value;
			if(username){
				username += ','+userdata.user[group[i]];
			}else{
				var username = userdata.user[group[i]];
			}
		}
		jQuery("._add input[name=\"save[recv]\"]").val(Acan.base.obj_json(group));
		jQuery("._add ._recv").text(username);
	}
	Acan.close('ajax_daily');
}
OA.daily.save = function(){
	var data = jQuery('.daily_add form').serializeArray();
	if(data[1].value==''){
		Acan.alert('请先选择接受人!',2000);
		return;
	}
	Acan.ajax_bg();
	var title = '发送日报';
	var css = {width:"640px",height:"auto"}
	jQuery.ajax({
		type: "POST",
		url: "/"+Aurl.Amodr+'-daily_add',
		data: data,
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			Acan.alert(data.msg);
			if(data.status == '1'){
				setTimeout("Acan.url.refresh(Aurl.Amodr+'-daily')",1300);
			}
			Acan.ajax_bg(0);
		}
	})
}
OA.meal = function(){}
OA.meal.order = function(id,name,price){
	var html = Ahtml.tag("form",{"onsubmit":"OA.meal.save(this);return false;"},
		Ahtml.tag("dl",{"class":"-dl"},
			Ahtml.tag("dt",{},"菜名:")+Ahtml.tag("dd",{},name)
			+Ahtml.tag("dt",{},"价格:")+Ahtml.tag("dd",{},price)
			+Ahtml.tag("dt",{},"份数:")+Ahtml.tag("dd",{},Ahtml.tag("input",{"type":"number","size":"3","name":"save[num]","value":1}))
			+Ahtml.tag("input",{"type":"hidden","size":"2","name":"save[mid]","value":id})
		)+Ahtml.tag("input",{"type":"submit","value":"预定"})
	);
	OA.daily.show("预定",html,{height:"320px",width:"320px"});
}
OA.meal.save = function(){
	var data = jQuery("#ajax_daily form").serialize();
	var url = Aurl.Amodr+'-save-one';
	jQuery.ajax({
		async : false,
		type:"POST",url:url,data:data,
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			rdata = data;
		}
	});
	if(typeof(rdata)=='object'){
		msg = rdata.msg;
		Acan.alert(decodeURI(rdata.msg),1500);
		if(rdata.status==0){
			if(!key){setTimeout('Acan.url.refresh()',1000);}
		}
		return;
	}else if(rdata==1){
		msg = '更新成功';
		Acan.close(this.Did);
	}else if(rdata==0){
		msg = '没有更新';
	}else{msg = '更新失败:'+rdata;}
	Acan.alert(msg,1000);
	if(!key){setTimeout('Acan.url.refresh()',1000);}
}
OA.meal.del = function(id){
	var url = Aurl.Amodr+'-del-'+id;
	jQuery.ajax({
		type:"POST",url:url,data:{"key":id},
		beforeSend: function(){Acan.alert('开始请求');},
		ajaxSend: function(){Acan.alert('发送请求');},
		success: function(data){
			Acan.alert(data,1000);
			setTimeout('Acan.url.refresh()',1000);
		}
	})
}
